package ejercicios;

import interfaces.tests.RetainPositiveNumbers;

import java.util.Arrays;

public class RetainPositiveNumbersImpl implements RetainPositiveNumbers {
	public int[] retainPositiveNumbers(int... a) {
		int[] result = new int[a.length];
		int index = 0;
		for (int x : a){
			if (x > 0){
				result[index++] = x;
			}
		}
		
		//as result is initialized with a.length, it is filled with white spaces
		//those white spaces needs to be filtered
		result = Arrays.copyOfRange(result, 0, index);
		//sort the numbers
		Arrays.sort(result);
		return result;
    }
}